package org.raymond.iworks.study.basic.designpattern.principle.openclose;

public class OpenClose1 {
    public static void main(String[] args) {
        GraphicEditor graphicEditor = new GraphicEditor();
        graphicEditor.drawCircle(new Circle());
        graphicEditor.drawRectangle(new Rectangle());
        // 使用方新增代码
        graphicEditor.drawTriangle(new Triangle());
    }
}

// 使用方
class GraphicEditor {
    public void drawShape(Shape s){
        if(s.m_type==1){
            drawRectangle(s);
        }else if(s.m_type==2){
            drawCircle(s);
        // 使用方新增代码
        }else if(s.m_type==3){
            drawTriangle(s);
        }
    }
    public void drawRectangle(Shape s){
        System.out.println("矩形");
    }
    public void drawCircle(Shape s){
        System.out.println("圆形");
    }
    // 使用方新增代码
    public void drawTriangle(Shape s){
        System.out.println("三角形");
    }
}
class Shape{
    int m_type;
}
class Rectangle extends Shape{
    Rectangle(){
        super.m_type=1;
    }
}
class Circle extends Shape{
    Circle(){
        super.m_type=2;
    }
}
// 服务方新增代码
class Triangle extends Shape {
    Triangle(){
        super.m_type=3;
    }
}
